<!--图书编辑-->
<html>
<head>
    <meta charset="utf-8">
    <!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
    <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
    <title id="title_name">编辑《 ${detail.name}》</title>
    <!--<link rel="stylesheet" href="css/bootstrap.min.css">-->
    <!--<script src="js/jquery-3.3.1.js"></script>-->
    <!--<script src="js/bootstrap.min.js" ></script>-->
    <!--<script src="js/getParameter.js" ></script>-->
    <style>
        body{
            background-color: rgb(240,242,245);
        }
    </style>

</head>
<body>

<div class="col-xs-6 col-md-offset-3" style="position: relative;top: 10%">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 id="h_name" class="panel-title">编辑《 ${detail.name}》</h3>
        </div>
        <div class="panel-body">
            <form method="post" id="updatebook" >
                <div class="input-group">
                    <span  class="input-group-addon">ID</span>
                    <input readonly type="text" class="form-control" name="book_id" id="bookId" value="${detail.bookId}">
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">书名</span>
                    <input type="text" class="form-control" name="name" id="name" value="${detail.name}">
                </div>
                <div class="input-group">
                    <span class="input-group-addon">作者</span>
                    <input type="text" class="form-control" name="author" id="author" value="${detail.author}" >
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">出版社</span>
                    <input type="text" class="form-control" name="publish" id="publish"  value="${detail.publish}" >
                </div>
                <div class="input-group">
                    <span class="input-group-addon">ISBN</span>
                    <input type="text" class="form-control" name="ISBN" id="isbn"  value="${detail.isbn}" >
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">简介</span>
                    <input type="text" class="form-control" name="introduction" id="introduction"  value="${detail.introduction}" >
                </div>
                <div class="input-group">
                    <span class="input-group-addon">语言</span>
                    <input type="text" class="form-control" name="language" id="language" value="${detail.language}" >
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">价格</span>
                    <input type="text" class="form-control" name="price"  id="price" value="${detail.price}">
                </div>
                <div class="input-group">
                    <span class="input-group-addon">出版日期</span>
                    <input type="text" class="form-control" name="pubdate" id="pubdate" value="${detail.pubdate}">
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">分类号</span>
                    <input type="text" class="form-control" name="class_id" id="classId" value="${detail.classId}">
                </div>
                <div class="input-group">
                    <span class="input-group-addon">书架号</span>
                    <input type="text" class="form-control" name="pressmark" id="pressmark" value="${detail.pressmark}">
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">状态</span>
                    <input type="text" class="form-control" name="state"  id="state" value="${detail.state}">
                </div>
                <input id="update_btn" type="submit" value="确定" class="btn btn-success btn-sm" class="text-left">

            </form>
        </div>
    </div>

</div>

</body>
<script>
    function mySubmit(flag){
        return flag;
    };
    $("#addbook").submit(function () {
        if($("#name").val()==''||$("#author").val()==''||$("#publish").val()==''||$("#isbn").val()==''||$("#introduction").val()==''||$("#language").val()==''||$("#price").val()==''||$("#pubdate").val()==''||$("#classId").val()==''||$("#pressmark").val()==''||$("#state").val()==''){
            alert("请填入完整图书信息！");
            return mySubmit(false);
        }
    });

    // var bookId = getParameter("bookId");
    var bookId = $.cookie("bookId");
    $.removeCookie("bookId");
    $(function () {
        $.ajax({
            type:"post",
            url:"book/findDetail",
            data:{"bookId":bookId},
            success:function (data) {
                $("#title_name").html("《"+data.name+"》");
                $("#h_name").html("《"+data.name+"》");

                $("#bookId").val(data.book_id);
                $("#name").val(data.name);
                $("#author").val(data.author);
                $("#publish").val(data.publish);
                $("#isbn").val(data.isbn);
                $("#introduction").val(data.introduction);
                $("#language").val(data.language);
                $("#price").val(data.price);
                $("#pubdate").val(format(data.pubdate));
                $("#classId").val(data.class_id);
                $("#pressmark").val(data.pressmark);
                $("#state").val(data.state);

            },dataType:"json"
        })
    })

    $("#update_btn").click(function () {
        $.ajax({
            type:"post",
            url:"book/updateBook",
            //map：修改输入框的信息包装对象
            data:$("#updatebook").serialize(),
            success:function (data) {
                if(data.flag){
                    alert("修改成功");
                    // location.href="admin_books.html"
                    $("#bookId").val("");
                    $("#middle").load("admin_books.html");
                }
            },dataType:"json"
        })
        return false;
    })

    function format(object) {
        var year = new Date(object).getFullYear(); //获取完整的年份(4位,1970-????)
        var month = new Date(object).getMonth() + 1; //获取当前月份(0-11,0代表1月)
        var day = new Date(object).getDate(); //获取当前日(1-31)
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var dateString =  year + "-" + month + "-" + day;
        return dateString;

    }
</script>
</html>
